package com.logicwin.Views;

import com.logicwin.RobotTravel.Main;
import com.logicwin.RobotTravel.R;
import com.logicwin.RobotTravel.Services.Impl.ServiceManager;
import com.logicwin.RobotTravel.utils.ConfigUtils;
import com.logicwin.RobotTravel.utils.Graphics;
import com.logicwin.RobotTravel.utils.SystemParams;
import com.logicwin.RobotTravel.Position.*;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class NavigateView extends View {
	private int x;
	private int y;
	private String current;
	private int color;
	private int fontSize;

	public NavigateView(Context context)
	{
		super(context);
		setupData(context);
	}
	public NavigateView(Context context, AttributeSet attrs) 
	{
		super(context, attrs);
		setupData(context);
	}
	
	private void setupData(Context context) {
		x = SystemParams.getWindowWidth(context);
		y = SystemParams.getWindowHeight(context) - ConfigUtils.getNewsTextSize(context) - 1;
		current = ConfigUtils.getNextNews();
		color = ConfigUtils.getNewsTextColor();
		fontSize = ConfigUtils.getNewsTextSize(context);
	}
	
	protected void onDraw(Canvas canvas)
	{		
		try
		{			
			Position position = ServiceManager.getPositoinService().getCurPosition();
			int posX;
			int posY;
			if(position != null){
				posX = position.getScreenX()*Main.screenWidth/800;
				posY = position.getScreenY()*Main.screenHeight/480;
				Graphics.drawImage(canvas, ((BitmapDrawable) getResources().getDrawable(R.drawable.dino)).getBitmap(), 
						posX, posY);
			}
/*			if(ServiceManager.getPositoinService().getPlay())
				Graphics.drawImage(canvas, ((BitmapDrawable) getResources().getDrawable(R.drawable.pause)).getBitmap(), 
						ServiceManager.getPositoinService().getControlX(), ServiceManager.getPositoinService().getControlY());
			else
				Graphics.drawImage(canvas, ((BitmapDrawable) getResources().getDrawable(R.drawable.start)).getBitmap(), 
						ServiceManager.getPositoinService().getControlX(), ServiceManager.getPositoinService().getControlY());*/
			/*Graphics.drawTextCenter(canvas, "", x, y, fontSize, color);*/
			if (x + Graphics.getTextSize(current, fontSize, color) > 0)
			{
				Graphics.drawText(canvas, current, x, y, fontSize, color);
				x -= ConfigUtils.getTextMoveSpeed(this.getContext());
			} else
			{
				current = ConfigUtils.getNextNews();
				x = SystemParams.getWindowWidth(this.getContext());
			}			
		}
		catch(Exception e)
		{
			Log.e("MobileMenuView::onDraw", e.toString());
		}
		
	}	
}
